package com.chat.datea.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.chat.datea.R;
import com.chat.datea.bean.SearchResultEntity;

import java.util.List;

/**
 * Created by Shura on 15/10/26.
 */
public class SongListViewAdapter extends BaseAdapter {

    private List<SearchResultEntity.ResultEntity.SongInfoEntity.SongListEntity> mSongListEntities;
    private Context mContext;

    public SongListViewAdapter(Context context, List<SearchResultEntity.ResultEntity.SongInfoEntity.SongListEntity> songlistEntities) {
        this.mContext = context;
        this.mSongListEntities = songlistEntities;
    }

    @Override
    public int getCount() {
        return mSongListEntities != null && mSongListEntities.size() > 0 ? mSongListEntities.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return mSongListEntities != null && mSongListEntities.size() > 0 ? mSongListEntities.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            // 初始化缓存组件
            viewHolder = new ViewHolder();
            // 通过布局加载器加载行布局
            convertView = LayoutInflater.from(mContext).inflate(R.layout.song_listview_item, null);
            viewHolder.song_name = (TextView) convertView.findViewById(R.id.song_name);
            viewHolder.singer_name = (TextView) convertView.findViewById(R.id.singer_name);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.singer_name.setText(mSongListEntities.get(position).getAuthor());
        viewHolder.song_name.setText(mSongListEntities.get(position).getTitle());
        return convertView;
    }

    public class ViewHolder {
        private TextView song_name, singer_name;
        private ImageView sq, mv;
    }
}
